package com.example.myapplication.slice;

import com.example.myapplication.ResourceTable;
import com.example.myapplication.beans.CartData;
import com.example.myapplication.provider.TabPageSliderProvider;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.PageSlider;
import ohos.agp.components.TabList;
import ohos.agp.components.Text;
import ohos.app.dispatcher.task.TaskPriority;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DetailAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_ability_detail);
        Button addBtn6 = (Button) findComponentById(ResourceTable.Id_shopcart_add_button);



        //获取传递的商品ID
        String productId = (String) intent.getParams().getParam("productId");
//        //将商品ID显示到商品详情⻚⾯的product_id_text的⽂本中
        Text text = (Text)findComponentById(ResourceTable.Id_product_detail_sku_text);
        text.setText(productId);

        String aproductId = (String) intent.getParams().getParam("aproductId");
//        //将商品ID显示到商品详情⻚⾯的product_id_text的⽂本中
        Text atext = (Text)findComponentById(ResourceTable.Id_product_detail_price_text);
        atext.setText(aproductId);

        Button addBtn  = (Button) findComponentById(ResourceTable.Id_shopcart_add_button);
        addBtn.setClickedListener(component -> {
            getGlobalTaskDispatcher(TaskPriority.DEFAULT).asyncDispatch(()->{
                //收集数据


//                Map<String , Object> params = new HashMap<>();
//                params.put("cartId",0);
//                params.put("cartNum",num);
//                params.put("productId",productId);
//                params.put("productPrice",selectSkuPrice);
//                params.put("skuId",selectSkuId);
//                params.put("skuProps","");
//                params.put("userId",userId);
//
//                //提交数据
//
//                if(resultVO.getCode() == 10000){
//                    System.out.println("--------------添加购物车成功！");
//                }

            });
        });
        addBtn6.setClickedListener(component -> {
            // 获取传递的商品ID
            Text text1 = (Text) findComponentById(ResourceTable.Id_product_detail_sku_text);
            String cartNum = text1.getText(); // 获取文本内容

            // 初始化参数
            Map<String, Object> params = new HashMap<>();
            params.put("cartId", 0);
            params.put("cartNum", cartNum);
            // 如果有其他参数需要添加，取消以下注释并设置值
            // params.put("productId", productId);
            // params.put("productPrice", selectSkuPrice);
            // params.put("skuId", selectSkuId);
            // params.put("skuProps", "");
            // params.put("userId", userId);

            // 保存数据到单例类
            CartData.getInstance().setCartParams(params);
            System.out.println("--------------添加购物车成功！");
        });

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
